﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            ///
            /// 日期
            ///
            //获取此刻时间信息存于now变量
            DateTime now = DateTime.Now;

            Console.WriteLine("当前日期为{0}", now);
            Console.WriteLine("本月的第{0}天：", now.Day);
            Console.WriteLine("今年是{0}", now.Year);
            Console.WriteLine("今天是今年的第{0}天", now.DayOfYear);
            Console.WriteLine("Today is {0}", now.DayOfWeek);
            Console.WriteLine("30 天后的日期是{0}", now.AddDays(30));
            Console.WriteLine("明年今天是{0}", now.AddYears(1));
            Console.WriteLine("十七秒后是{0}", now.AddSeconds(17));
            Console.WriteLine("两个月前今天的前一天{0}", now.AddMonths(-2).AddDays(-1));
            Console.WriteLine("SEVENTEEN出道日{0}", now.AddYears(-5).AddDays(-2).ToShortDateString());

            Console.WriteLine();

            //获取当前的短日期
            Console.WriteLine(now.ToShortDateString());
            //获取当前的短时间
            Console.WriteLine(now.ToShortTimeString());
            //获取当前的长日期
            Console.WriteLine(now.ToLongDateString());
            //获取当前的长时间
            Console.WriteLine(now.ToLongTimeString());

            Console.WriteLine();

            string first = "2020-3-01";
            DateTime second = Convert.ToDateTime(first);
            DateTime lastday = second.AddDays(-1);
            Console.WriteLine(lastday.ToShortDateString());

            Console.WriteLine();

            ///
            /// 字符串
            ///
            string song = "Don't wanna cry";
            Console.WriteLine("此歌名有{0}个字",song.Length);

            Console.WriteLine("第一次出现的位置{0}", song.IndexOf("a"));
            Console.WriteLine("最后出现的位置{0}",song.LastIndexOf("a"));

            Console.WriteLine("是否为开头字：{0}", song.StartsWith("D"));
            Console.WriteLine("是否为结束字：{0}",song.EndsWith("y"));

            Console.WriteLine("指定位置的字符串移除{0}", song.Remove(14));

            string book = "你好明天";
            Console.WriteLine(book.Substring(2,2));
            Console.WriteLine(book.Insert(4,"呀"));
            Console.WriteLine(book.Replace("你","ni"));

            Console.WriteLine();

            Console.WriteLine("请输入邮箱号码");
            string str = Console.ReadLine();
            if (str.IndexOf("@") != -1)
            {
                Console.WriteLine("字符串中含有@，其出现的位置是{0}", str.IndexOf(" ") + 1);
            }
            else
            {
                Console.WriteLine("字符串中不含有@");
            }






        }
    }
}
